#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>

int main()
{
	int server_fd,client_fd;
	int server_len,client_len;
        struct sockaddr_un server_add,client_add;


	unlink("socket_server");
	server_fd=socket(AF_UNIX,SOCK_STREAM,0);
	if(server_fd==-1)
	{
		printf("error1\n");
		return -1;
	}
	
	server_len=sizeof(server_add);
	server_add.sun_family=AF_UNIX;
	strcpy(server_add.sun_path,"socket_server");
	//bind(server_fd,(struct sockaddr*)&server_add,server_len);
	if(bind(server_fd,(struct sockaddr*)&server_add,server_len)==-1)
	{
		printf("error bind\n");
		return -1;
	}

	//listen(server_fd,5);
	if(listen(server_fd,5)==-1)
	{
		printf("error listen\n");
		return -1;
	}
	while(1)
	{
		char ch;
		printf("server starting\n");

		client_len=sizeof(client_add);
		client_fd=accept(server_fd,(struct sockaddr*)&client_add,(socklen_t*)&client_len);
		if(client_fd==-1)
		{
			printf("socket invalid!\n");
			return -1;
		}		

		read(client_fd,&ch,1);
		ch++;
		write(client_fd,&ch,1);
		close(client_fd);
	}
	return 0;
}
